/** @jsxImportSource @emotion/react */
import * as React from "react";
import {OriginalViewProps, } from "../../common/base";
import {EntranceSetup, config设备概况, config观测数据,} from "./orcBase";
import {createItem, } from "../../common/eHelper";
import {useRecordList} from "../../hook/useRecordList";
import {setupItemAreaRoute} from "./orcIspConfig";
import {EditStorageContext} from "../../StorageContext";
import {Text, useTheme} from "customize-easy-ui-component";
import {ItemInstrumentTable} from "../../common/Instrument";
import {FrontCover, ItemConclusion} from "../../mobilecr/editorIN";
import {SiteConditionSund,} from "../../elevator/sundryDj/editor";
import {GenCode} from "../../common/GenCode";
import {ActionMapItem} from "../../common/ActionMapItem";
import {config记录} from "./FormatOriginal";
import {RecheckEditor} from "../../common/editor";
import {DeviceSurveyD} from "../../crane/editor";
import {MeasureJudgmentMem, MemoEditor, OtherIspItemSet} from "../editor";

//【可直接】在这里改： "pr":"※","ses":6  "r":3,"s":1,
const defFrameM={
    'Rec3ClRep2Cl': `{ "mg":2, "dcl":"","cl":"",
         "sk":[ {"no":"7.25.0", "r":0,"ses":8 }, 0, 0,0,0,0,
           { "r":2}
         ]
    }`,
};
//正式报告的PDF直接复制出来的：
const defTitle=
    `7.9 集电器
`;
//原始记录复制来的; 分隔开两个子项目的文本： 一个空行！【特别小心】有没有空格的的看起来像空行!!!
const defDesc=
    `（1）电刷和滑环应接触良好，外露的集电器必须设防雨
`;


export const tItems现场=[
    ['1、温度、湿度、照明气候',{f:'T',
        N: <Text>1、温度、湿度、照明及室外气候条件能满足游乐设施正常运行及检验作业要求；</Text>},],
    ['2、电气系统的电压',{f:'V',
        N: <Text>2、输入电气系统的电压正常，电压波动在允许值以内；</Text>},],
    ['3、现场没有无关的物品',{f:'s',
        N: <Text>3、检验现场不应有与游乐设施工作无关的物品和设备，并应放置表明现场正在进行检验的警示牌。</Text>},],
];
const 备注选=[
    "设备应监护使用",
    "作业人员持证后本设备才能投入使用",
    "设备应监护使用；作业人员持证后本设备才能投入使用"
];

//原版本记录比较怪异： 八、复检记录和不合格表分离，复检结果 结论还单独设立的，而且仪器表2份，附录A1 A2现场检测条件2份；四、首次检验不合格项目记录
//另外还附上： 九、复检综合结论 十、复检备注 “？？” 像是：复检的没有重新做一份报告的模式。五、综合结论六、备注
const recordPrintList =[
    createItem('Entrance', <EntranceSetup/>),
    createItem('FrontCover', <FrontCover/>),
    createItem('Instrument', <ItemInstrumentTable label={'一、主要检验仪器设备性能检查'} />),
    createItem('Survey', <DeviceSurveyD config={config设备概况} label={'二、设备概况'}/>),
    createItem('_OtherItem', <OtherIspItemSet baseSeq={47} label={'检验项目: 14 其它项目的设置'}>
            注：※为重要项，其它为一般项。
          </OtherIspItemSet>),
    createItem('Item', null),
    createItem('ReCheck', <RecheckEditor  label={'四、检验不符合记录及整改情况确认'} setup={setupItemAreaRoute}/>),
    createItem('Conclusion', <ItemConclusion startd={false} label={'五、综合结论'} nxtstyp={'检验'}/>),
    createItem('Witness', <MemoEditor label={'六、备注'} datalist={备注选}/>),
    createItem('Measure', <MeasureJudgmentMem config={config观测数据}  label={'七、观测数据及测量结果记录'}>
        注：本表所列项目检验人员无测量的不记录
        </MeasureJudgmentMem>),

    createItem('SiteCondition', <SiteConditionSund config={tItems现场} label={'附录A：现场检验条件确认'}/>),
];
if(process.env.REACT_APP_TEST==='true')  recordPrintList.splice(0,0,createItem('GenCode', <GenCode type='Rec3ClRep2Cl'
                                             frameMod={defFrameM} defTitle={defTitle} defDesc={defDesc}/>));


export const OriginalView=
  React.forwardRef((
    { action,  verId, repId='', rep,}
    :OriginalViewProps, ref
  ) => {
    const context =React.useContext(EditStorageContext);
    if(context == null)    throw new Error("EditStorageContext没有提供");
    const {storage, } =context;
    const theme = useTheme();
    const recordPrintListNow =React.useMemo(() => {
      let routeAreas=[] as any[];
      const impressionismAs =setupItemAreaRoute({rep, orc:storage, theme});
      let extendTags =Reflect.ownKeys(impressionismAs) as string[];
      const oldItCount=recordPrintList.length;
      let prevpos=0;
      for(let p=0; p<oldItCount; p++){
        if(extendTags.indexOf(recordPrintList[p].itemArea)>=0){     //需要展开 扩充的标签
            routeAreas=routeAreas.concat(recordPrintList.slice(prevpos,p));
            const itemConfigs= impressionismAs?.[recordPrintList[p].itemArea];
            let seq = 0;
            let moreItems = [] as any;
            itemConfigs.forEach((area, x) => {
              seq += 1;
              const rowHead =<ActionMapItem key={seq} alone={false} editAreasConf={itemConfigs}
                                                    index={x} sureD editIts={config记录} />;
              moreItems.push(createItem(area.tag, rowHead));
            });
            routeAreas=routeAreas.concat(moreItems);
            prevpos=p+1;
        }
      }
      routeAreas=routeAreas.concat(recordPrintList.slice(prevpos));
      return routeAreas;
    }, [verId, repId,rep, storage?._Oitems, theme]);

    const {list}=useRecordList(ref,rep,recordPrintListNow,action,verId);
    return <React.Fragment>
      {list}
        {/*      <Button  intent="primary"
                   onPress={(e) => { handleSubmit!();
                   }}
          >送打印转换器
          </Button>*/}
    </React.Fragment>;
  } );
